package com.wxzz.elearing.comment.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.comment.dto.QuestionsAnswersDto;
import com.wxzz.elearing.comment.entity.Comment;
import com.wxzz.elearing.comment.service.IGiveLikeService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx-give-Like")
@Api(tags = "问答点赞及热度接口(小程序)")
public class WxGiveLikeController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private IGiveLikeService iGiveLikeService;

    @ApiOperation(value = "问答点赞及热度接口(小程序)", notes = "问答点赞及热度接口(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "giveLike", method = RequestMethod.POST)
    public ReturnVO giveLike(@RequestBody Comment comment, @RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        comment.setWxUserId(jsonObject.getLong("id"));
//        comment.setWxUserId(1392071664227999745L);
        return iGiveLikeService.giveLike(comment);
    }
}
